package io;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 练习:向文件中写入字符数据并读取
 */
public class Test1 {
    public static void main(String[] args) throws IOException {
        //写入文件
        /*
        FileOutputStream fos=new FileOutputStream("demo.txt");
        //第二个参数boolean表示文件的操作模式,true即为追加模式,不写默认为false为覆盖模式
        //FileOutputStream fos = new FileOutputStream("demo.txt", true);
        for (char c = 'a'; c <= 'z'; c++) {
            fos.write(c);
        }
        System.out.println("写入成功");
        fos.close();
         */

        //读取文件
        FileInputStream fis=new FileInputStream("demo.txt");
        int d;
        while ((d=fis.read())!=-1){
            System.out.print((char)d);
        }
        fis.close();
    }
}
